home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / game / shoot / inv.lha / inv.c < prev    next >
C/C++ Source or Header  |  1970-01-28  |  23KB  |  973 lines

  1.  
  2. /* written by yair goldfinger (amigo)
  3.    yairgo@libra.tau.ac.il
  4. */
  5.  
  6.  
  7.  
  8. #define BUserStuff SHORT
  9. #include <intuition/intuition.h>
  10. /* Include this file since you are using sprites: */
  11. #include <graphics/sprite.h>
  12. #include <exec/ports.h>
  13. #include <exec/types.h>
  14. #include <proto/all.h>
  15. #include <graphics/gels.h>
  16. #include <graphics/collide.h>
  17. #include <stdlib.h>
  18. #include <exec/memory.h>
  19. #include <libraries/dos.h>
  20. #include <stdio.h>
  21.  
  22. #define MAXBOBS 8
  23.  
  24. /* They will move one pixel each time: */
  25. #define SPEED 4
  26. VOID quit(int return_code);
  27. VOID bordercheck(struct VSprite *vs,LONG borderflags);
  28. VOID freeBob(struct Bob *bob);
  29. VOID gotit(struct VSprite *gelA,struct VSprite *gelB);
  30. VOID handle_shoot(struct Bob *shoot[],struct Window *win);
  31. VOID bobDrawGlist(struct Window *win);
  32. struct Bob *makeBob(SHORT wordwidth,SHORT lineheight,SHORT x,
  33.                     SHORT y, WORD *imagedata,WORD memask,
  34.                     WORD hitmask,SHORT id);
  35. VOID process_window(struct Window *win , struct Bob *ship_bob,
  36.                     struct Bob *enemy_bobs[] );
  37.  
  38. struct VSprite *makeVSprite(WORD y , WORD x , WORD flags, WORD width,
  39.                             WORD height, WORD depth , WORD memask,
  40.                             WORD hitmask, WORD *imagedata ,WORD *sprcolors);
  41. struct GelsInfo *setupGelSys(struct RastPort *rPort, BYTE reserved);
  42. VOID cleanupGelSys(struct GelsInfo *gInfo, struct RastPort *rPort);
  43. VOID do_bobs(struct Window *win);
  44. VOID freeVSprite(struct VSprite *vsprite);
  45. VOID main();
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. /* Declare the functions we are going to use: */
  55.  
  56. struct IntuitionBase *IntuitionBase = NULL;
  57.  
  58. struct GfxBase *GfxBase = NULL;
  59.  
  60. int return_code;
  61. /* Declare and initialize your NewWindow structure: */
  62. struct NewWindow myNewWindow=
  63. {
  64.   20,            /* LeftEdge    x position of the window. */
  65.   25,            /* TopEdge     y positio of the window. */
  66.   320,           /* Width       320 pixels wide. */
  67.   100,           /* Height      100 lines high. */
  68.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  69.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  70.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  71.   RAWKEY,        /*             user has selected the Close window gad, */
  72.                  /*             or if the user has pressed a key. */
  73.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  74.   WINDOWCLOSE|   /*             Close Gadget. */
  75.   WINDOWDRAG|    /*             Drag gadget. */
  76.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  77.   ACTIVATE,      /*             The window should be Active when opened. */
  78.   NULL,          /* FirstGadget No Custom gadgets. */
  79.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  80.   "space v-0.3 by Yair Goldfinger",  /* Title       Title of the window. */
  81.   NULL,          /* Screen      Connected to the Workbench Screen. */
  82.   NULL,          /* BitMap      No Custom BitMap. */
  83.   80,            /* MinWidth    We will not allow the window to become */
  84.   30,            /* MinHeight   smaller than 80 x 30, and not bigger */
  85.   300,           /* MaxWidth    than 300 x 200. */
  86.   200,           /* MaxHeight */
  87.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  88. };
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. /********************************************************/
  96. /* 1. Declare and initialize some sprite graphics data: */
  97. /********************************************************/
  98. /* Sprite data for a ship: */
  99. /* (6 frames, 4 different images: 1 2 3 4 3 2) */
  100. UWORD chip good_ship_data[] =
  101.    {
  102.   0x00F0, 0x0000,
  103.    0x00F0, 0x0000,
  104.    0x03FC, 0x0000,
  105.    0x03FC, 0x0000,
  106.    0x0000, 0x0000,
  107.    0x0000, 0x0000,
  108.    0x0000, 0x0000,
  109.    0x0000, 0x0000,
  110.    /**/
  111.    0x0000, 0x0000,
  112.    0x0000, 0x0000,
  113.    0x03FC, 0x0000,
  114.    0x03FC, 0x0000,
  115.    0xFFFF, 0xF000,
  116.    0xFFFF, 0xF000,
  117.    0xFFFF, 0xF000,
  118.    0xFFFF, 0xF000,
  119.    };
  120.  
  121.  
  122. /* for the vsprites */
  123. UWORD chip ship_data[12][72]=
  124. {
  125.   {
  126.   0x0000, 0x0000, 0x0000,
  127.    0x0000, 0x0000, 0x0000,
  128.    0x0000, 0x0000, 0x0000,
  129.    0x0006, 0x1FF8, 0x0000,
  130.    0x000F, 0x783E, 0x0000,
  131.    0x03EF, 0x7C07, 0x0000,
  132.    0x03EF, 0x7FFF, 0x0000,
  133.    0x006F, 0x7FFE, 0x0000,
  134.    0x0000, 0x7FF8, 0x0000,
  135.    0x0000, 0x0000, 0x0000,
  136.    0x0000, 0x0000, 0x0000,
  137.    0x0000, 0x0000, 0x0000,
  138.    /**/
  139.    0x07FF, 0xFE00, 0x0000,
  140.    0x0006, 0x0000, 0x0000,
  141.    0x0006, 0x1FF8, 0x0000,
  142.    0xC019, 0xE006, 0x0000,
  143.    0xC7F0, 0x87C1, 0x8000,
  144.    0xFC10, 0x83F8, 0x8000,
  145.    0xC410, 0x8000, 0x8000,
  146.    0xC790, 0x8001, 0x8000,
  147.    0x007F, 0x8006, 0x0000,
  148.    0x0010, 0x7FF8, 0x0000,
  149.    0x0060, 0x0041, 0x8000,
  150.    0x03FF, 0xFFFE, 0x0000, 
  151.   },
  152.   {
  153.    0x0000, 0x0000, 0x0000,
  154.    0x0000, 0x0000, 0x0000,
  155.    0x0000, 0x0000, 0x0000,
  156.    0x0006, 0x1FF8, 0x0000,
  157.    0x000F, 0x783E, 0x0000,
  158.    0x03EF, 0x7C07, 0x0000,
  159.    0x03EF, 0x7FFF, 0x0000,
  160.    0x006F, 0x7FFE, 0x0000,
  161.    0x0000, 0x7FF8, 0x0000,
  162.    0x0000, 0x0000, 0x0000,
  163.    0x0000, 0x0000, 0x0000,
  164.    0x0000, 0x0000, 0x0000,
  165.    /**/
  166.    0x03FF, 0xFC00, 0x0000,
  167.    0x0006, 0x0000, 0x0000,
  168.    0x0006, 0x1FF8, 0x0000,
  169.    0x0019, 0xE006, 0x0000,
  170.    0xC7F0, 0x87C1, 0x8000,
  171.    0xFC10, 0x83F8, 0x8000,
  172.    0xC410, 0x8000, 0x8000,
  173.    0x0790, 0x8001, 0x8000,
  174.    0x007F, 0x8006, 0x0000,
  175.    0x0010, 0x7FF8, 0x0000,
  176.    0x0060, 0x0041, 0x8000,
  177.    0x03FF, 0xFFFE, 0x0000,
  178.   },
  179.   {
  180.    0x0000, 0x0000, 0x0000,
  181.    0x0000, 0x0000, 0x0000,
  182.    0x0000, 0x0000, 0x0000,
  183.    0x0006, 0x1FF8, 0x0000,
  184.    0x000F, 0x783E, 0x0000,
  185.    0x03EF, 0x7C07, 0x0000,
  186.    0x03EF, 0x7FFF, 0x0000,
  187.    0x006F, 0x7FFE, 0x0000,
  188.    0x0000, 0x7FF8, 0x0000,
  189.    0x0000, 0x0000, 0x0000,
  190.    0x0000, 0x0000, 0x0000,
  191.    0x0000, 0x0000, 0x0000,
  192.    /**/
  193.    0x01FF, 0xF800, 0x0000,
  194.    0x0006, 0x0000, 0x0000,
  195.    0x0006, 0x1FF8, 0x0000,
  196.    0xC019, 0xE006, 0x0000,
  197.    0xC7F0, 0x87C1, 0x8000,
  198.    0xFC10, 0x83F8, 0x8000,
  199.    0xC410, 0x8000, 0x8000,
  200.    0xC790, 0x8001, 0x8000,
  201.    0x007F, 0x8006, 0x0000,
  202.    0x0010, 0x7FF8, 0x0000,
  203.    0x0060, 0x0041, 0x8000,
  204.    0x03FF, 0xFFFE, 0x0000,
  205.  
  206.   },
  207.   {
  208.    0x0000, 0x0000, 0x0000,
  209.    0x0000, 0x0000, 0x0000,
  210.    0x0000, 0x0000, 0x0000,
  211.    0x0006, 0x1FF8, 0x0000,
  212.    0x000F, 0x783E, 0x0000,
  213.    0x03EF, 0x7C07, 0x0000,
  214.    0x03EF, 0x7FFF, 0x0000,
  215.    0x006F, 0x7FFE, 0x0000,
  216.    0x0000, 0x7FF8, 0x0000,
  217.    0x0000, 0x0000, 0x0000,
  218.    0x0000, 0x0000, 0x0000,
  219.    0x0000, 0x0000, 0x0000,
  220.    /**/
  221.    0x00FF, 0xF000, 0x0000,
  222.    0x0006, 0x0000, 0x0000,
  223.    0x0006, 0x1FF8, 0x0000,
  224.    0x0019, 0xE006, 0x0000,
  225.    0xC7F0, 0x87C1, 0x8000,
  226.    0xFC10, 0x83F8, 0x8000,
  227.    0xC410, 0x8000, 0x8000,
  228.    0x0790, 0x8001, 0x8000,
  229.    0x007F, 0x8006, 0x0000,
  230.    0x0010, 0x7FF8, 0x0000,
  231.    0x0060, 0x0041, 0x8000,
  232.    0x03FF, 0xFFFE, 0x0000,
  233.  
  234.    },
  235.   {   
  236.     0x0000, 0x0000, 0x0000,
  237.    0x0000, 0x0000, 0x0000,
  238.    0x0000, 0x0000, 0x0000,
  239.    0x0006, 0x1FF8, 0x0000,
  240.    0x000F, 0x783E, 0x0000,
  241.    0x03EF, 0x7C07, 0x0000,
  242.    0x03EF, 0x7FFF, 0x0000,
  243.    0x006F, 0x7FFE, 0x0000,
  244.    0x0000, 0x7FF8, 0x0000,
  245.    0x0000, 0x0000, 0x0000,
  246.    0x0000, 0x0000, 0x0000,
  247.    0x0000, 0x0000, 0x0000,
  248.    /**/
  249.    0x01FF, 0xF800, 0x0000,
  250.    0x0006, 0x0000, 0x0000,
  251.    0x0006, 0x1FF8, 0x0000,
  252.    0xC019, 0xE006, 0x0000,
  253.    0xC7F0, 0x87C1, 0x8000,
  254.    0xFC10, 0x83F8, 0x8000,
  255.    0xC410, 0x8000, 0x8000,
  256.    0xC790, 0x8001, 0x8000,
  257.    0x007F, 0x8006, 0x0000,
  258.    0x0010, 0x7FF8, 0x0000,
  259.    0x0060, 0x0041, 0x8000,
  260.    0x03FF, 0xFFFE, 0x0000,
  261.  
  262.   },
  263.   {
  264.     0x0000, 0x0000, 0x0000,
  265.    0x0000, 0x0000, 0x0000,
  266.    0x0000, 0x0000, 0x0000,
  267.    0x0006, 0x1FF8, 0x0000,
  268.    0x000F, 0x783E, 0x0000,
  269.    0x03EF, 0x7C07, 0x0000,
  270.    0x03EF, 0x7FFF, 0x0000,
  271.    0x006F, 0x7FFE, 0x0000,
  272.    0x0000, 0x7FF8, 0x0000,
  273.    0x0000, 0x0000, 0x0000,
  274.    0x0000, 0x0000, 0x0000,
  275.    0x0000, 0x0000, 0x0000,
  276.    /**/
  277.    0x03FF, 0xFC00, 0x0000,
  278.    0x0006, 0x0000, 0x0000,
  279.    0x0006, 0x1FF8, 0x0000,
  280.    0x0019, 0xE006, 0x0000,
  281.    0xC7F0, 0x87C1, 0x8000,
  282.    0xFC10, 0x83F8, 0x8000,
  283.    0xC410, 0x8000, 0x8000,
  284.    0x0790, 0x8001, 0x8000,
  285.    0x007F, 0x8006, 0x0000,
  286.    0x0010, 0x7FF8, 0x0000,
  287.    0x0060, 0x0041, 0x8000,
  288.    0x03FF, 0xFFFE, 0x0000,
  289.  
  290.   },
  291.  {
  292.    0x0000, 0x0000, 0x0000,
  293.    0x0000, 0x0000, 0x0000,
  294.    0x0000, 0x0000, 0x0000,
  295.    0x0FFC, 0x3000, 0x0000,
  296.    0x3E0F, 0x7800, 0x0000,
  297.    0x701F, 0x7BE0, 0x0000,
  298.    0x7FFF, 0x7BE0, 0x0000,
  299.    0x3FFF, 0x7B00, 0x0000,
  300.    0x0FFF, 0x0000, 0x0000,
  301.    0x0000, 0x0000, 0x0000,
  302.    0x0000, 0x0000, 0x0000,
  303.    0x0000, 0x0000, 0x0000,
  304.    /**/
  305.    0x003F, 0xFFF0, 0x0000,
  306.    0x0000, 0x3000, 0x0000,
  307.    0x0FFC, 0x3000, 0x0000,
  308.    0x3003, 0xCC01, 0x8000,
  309.    0xC1F0, 0x87F1, 0x8000,
  310.    0x8FE0, 0x841F, 0x8000,
  311.    0x8000, 0x8411, 0x8000,
  312.    0xC000, 0x84F1, 0x8000,
  313.    0x3000, 0xFF00, 0x0000,
  314.    0x0FFF, 0x0400, 0x0000,
  315.    0xC100, 0x0300, 0x0000,
  316.    0x3FFF, 0xFFE0, 0x0000,
  317.    },
  318.   {
  319.    0x0000, 0x0000, 0x0000,
  320.    0x0000, 0x0000, 0x0000,
  321.    0x0000, 0x0000, 0x0000,
  322.    0x0FFC, 0x3000, 0x0000,
  323.    0x3E0F, 0x7800, 0x0000,
  324.    0x701F, 0x7BE0, 0x0000,
  325.    0x7FFF, 0x7BE0, 0x0000,
  326.    0x3FFF, 0x7B00, 0x0000,
  327.    0x0FFF, 0x0000, 0x0000,
  328.    0x0000, 0x0000, 0x0000,
  329.    0x0000, 0x0000, 0x0000,
  330.    0x0000, 0x0000, 0x0000,
  331.    /**/
  332.    0x001F, 0xFFE0, 0x0000,
  333.    0x0000, 0x3000, 0x0000,
  334.    0x0FFC, 0x3000, 0x0000,
  335.    0x3003, 0xCC00, 0x0000,
  336.    0xC1F0, 0x87F1, 0x8000,
  337.    0x8FE0, 0x841F, 0x8000,
  338.    0x8000, 0x8411, 0x8000,
  339.    0xC000, 0x84F0, 0x0000,
  340.    0x3000, 0xFF00, 0x0000,
  341.    0x0FFF, 0x0400, 0x0000,
  342.    0xC100, 0x0300, 0x0000,
  343.    0x3FFF, 0xFFE0, 0x0000,
  344.    },
  345. {
  346.    0x0000, 0x0000, 0x0000,
  347.    0x0000, 0x0000, 0x0000,
  348.    0x0000, 0x0000, 0x0000,
  349.    0x07FE, 0x1800, 0x0000,
  350.    0x1F07, 0xBC00, 0x0000,
  351.    0x380F, 0xBDF0, 0x0000,
  352.    0x3FFF, 0xBDF0, 0x0000,
  353.    0x1FFF, 0xBD80, 0x0000,
  354.    0x07FF, 0x8000, 0x0000,
  355.    0x0000, 0x0000, 0x0000,
  356.    0x0000, 0x0000, 0x0000,
  357.    0x0000, 0x0000, 0x0000,
  358.    /**/
  359.    0x000F, 0xFFE0, 0x0000,
  360.    0x0000, 0x3800, 0x0000,
  361.    0x0FFE, 0x3800, 0x0000,
  362.    0x3801, 0xE601, 0x8000,
  363.    0xE0F8, 0x43F9, 0x8000,
  364.    0xC7F0, 0x420F, 0x8000,
  365.    0xC000, 0x4209, 0x8000,
  366.    0xE000, 0x4279, 0x8000,
  367.    0x3800, 0x7F80, 0x0000,
  368.    0x0FFF, 0x8600, 0x0000,
  369.    0xE180, 0x0380, 0x0000,
  370.    0x3FFF, 0xFFF0, 0x0000,
  371.    },
  372.    {
  373.    0x0000, 0x0000, 0x0000,
  374.    0x0000, 0x0000, 0x0000,
  375.    0x0000, 0x0000, 0x0000,
  376.    0x0FFC, 0x3000, 0x0000,
  377.    0x3E0F, 0x7800, 0x0000,
  378.    0x701F, 0x7BE0, 0x0000,
  379.    0x7FFF, 0x7BE0, 0x0000,
  380.    0x3FFF, 0x7B00, 0x0000,
  381.    0x0FFF, 0x0000, 0x0000,
  382.    0x0000, 0x0000, 0x0000,
  383.    0x0000, 0x0000, 0x0000,
  384.    0x0000, 0x0000, 0x0000,
  385.    /**/
  386.    0x0007, 0xFF80, 0x0000,
  387.    0x0000, 0x3000, 0x0000,
  388.    0x0FFC, 0x3000, 0x0000,
  389.    0x3003, 0xCC00, 0x0000,
  390.    0xC1F0, 0x87F1, 0x8000,
  391.    0x8FE0, 0x841F, 0x8000,
  392.    0x8000, 0x8411, 0x8000,
  393.    0xC000, 0x84F0, 0x0000,
  394.    0x3000, 0xFF00, 0x0000,
  395.    0x0FFF, 0x0400, 0x0000,
  396.    0xC100, 0x0300, 0x0000,
  397.    0x3FFF, 0xFFE0, 0x0000,
  398.    },
  399.  {
  400.    0x0000, 0x0000, 0x0000,
  401.    0x0000, 0x0000, 0x0000,
  402.    0x0000, 0x0000, 0x0000,
  403.    0x0FFC, 0x3000, 0x0000,
  404.    0x3E0F, 0x7800, 0x0000,
  405.    0x701F, 0x7BE0, 0x0000,
  406.    0x7FFF, 0x7BE0, 0x0000,
  407.    0x3FFF, 0x7B00, 0x0000,
  408.    0x0FFF, 0x0000, 0x0000,
  409.    0x0000, 0x0000, 0x0000,
  410.    0x0000, 0x0000, 0x0000,
  411.    0x0000, 0x0000, 0x0000,
  412.    /**/
  413.    0x000F, 0xFFC0, 0x0000,
  414.    0x0000, 0x3000, 0x0000,
  415.    0x0FFC, 0x3000, 0x0000,
  416.    0x3003, 0xCC01, 0x8000,
  417.    0xC1F0, 0x87F1, 0x8000,
  418.    0x8FE0, 0x841F, 0x8000,
  419.    0x8000, 0x8411, 0x8000,
  420.    0xC000, 0x84F1, 0x8000,
  421.    0x3000, 0xFF00, 0x0000,
  422.    0x0FFF, 0x0400, 0x0000,
  423.    0xC100, 0x0300, 0x0000,
  424.    0x3FFF, 0xFFE0, 0x0000,
  425.    },
  426.    {
  427.    0x0000, 0x0000, 0x0000,
  428.    0x0000, 0x0000, 0x0000,
  429.    0x0000, 0x0000, 0x0000,
  430.    0x0FFC, 0x3000, 0x0000,
  431.    0x3E0F, 0x7800, 0x0000,
  432.    0x701F, 0x7BE0, 0x0000,
  433.    0x7FFF, 0x7BE0, 0x0000,
  434.    0x3FFF, 0x7B00, 0x0000,
  435.    0x0FFF, 0x0000, 0x0000,
  436.    0x0000, 0x0000, 0x0000,
  437.    0x0000, 0x0000, 0x0000,
  438.    0x0000, 0x0000, 0x0000,
  439.    /**/
  440.    0x001F, 0xFFE0, 0x0000,
  441.    0x0000, 0x3000, 0x0000,
  442.    0x0FFC, 0x3000, 0x0000,
  443.    0x3003, 0xCC00, 0x0000,
  444.    0xC1F0, 0x87F1, 0x8000,
  445.    0x8FE0, 0x841F, 0x8000,
  446.    0x8000, 0x8411, 0x8000,
  447.    0xC000, 0x84F0, 0x0000,
  448.    0x3000, 0xFF00, 0x0000,
  449.    0x0FFF, 0x0400, 0x0000,
  450.    0xC100, 0x0300, 0x0000,
  451.    0x3FFF, 0xFFE0, 0x0000,
  452.    },
  453.  
  454. };
  455.  
  456. WORD chip shoot_image[] = {
  457.    0xF000,
  458.    /**/
  459.    0xF000, 
  460.   };
  461.  
  462. /* 4. Declare a GelsInfo structure: */
  463. struct GelsInfo *my_ginfo;
  464. struct Window       *win;
  465. struct Bob  *enemy_bobs[ MAXBOBS ];
  466. struct Bob *ship_bob;
  467. VOID main()
  468. {
  469.  
  470.  
  471. return_code = RETURN_OK;
  472.  
  473. if (NULL == (GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",33L)))
  474.     return_code = RETURN_FAIL;
  475. else
  476.     {
  477.     if (NULL == (IntuitionBase =
  478.             (struct IntuitionBase *)OpenLibrary("intuition.library",33L)))
  479.         return_code = RETURN_FAIL;
  480.     else
  481.         {
  482.         if (NULL == (win = OpenWindow(&myNewWindow)))
  483.             return_code = RETURN_WARN;
  484.         else
  485.             {
  486.             do_bobs(win);
  487.  
  488.             CloseWindow(win);
  489.             }
  490.         CloseLibrary(IntuitionBase);
  491.         }
  492.     CloseLibrary(GfxBase);
  493.     }
  494. exit(return_code);
  495. }
  496.  
  497. VOID freeVSprite(struct VSprite *vsprite)
  498. {
  499. LONG    line_size;
  500. LONG    plane_size;
  501.  
  502. line_size = (LONG)sizeof(WORD) * vsprite->Width;
  503. plane_size = line_size * vsprite->Height;
  504.  
  505. FreeMem(vsprite->BorderLine, line_size);
  506. FreeMem(vsprite->CollMask, plane_size);
  507.  
  508. FreeMem(vsprite, (LONG)sizeof(*vsprite));
  509. }
  510.  
  511.  
  512.  
  513.  
  514. VOID cleanupGelSys(struct GelsInfo *gInfo, struct RastPort *rPort)
  515. {
  516. rPort->GelsInfo = NULL;
  517.  
  518. FreeMem(gInfo->collHandler, (LONG)sizeof(struct collTable));
  519. FreeMem(gInfo->lastColor, (LONG)sizeof(LONG) * 8);
  520. FreeMem(gInfo->nextLine, (LONG)sizeof(WORD) * 8);
  521. FreeMem(gInfo->gelHead, (LONG)sizeof(struct VSprite));
  522. FreeMem(gInfo->gelTail, (LONG)sizeof(struct VSprite));
  523. FreeMem(gInfo, (LONG)sizeof(*gInfo));
  524. }
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533. struct GelsInfo *setupGelSys(struct RastPort *rPort, BYTE reserved)
  534. {
  535. struct GelsInfo *gInfo;
  536. struct VSprite  *vsHead;
  537. struct VSprite  *vsTail;
  538.  
  539. if (NULL != (gInfo =
  540.     (struct GelsInfo *)AllocMem((LONG)sizeof(struct GelsInfo), MEMF_CLEAR)))
  541.     {
  542.     if (NULL != (gInfo->nextLine =
  543.         (WORD *)AllocMem((LONG)sizeof(WORD) * 8, MEMF_CLEAR)))
  544.         {
  545.         if (NULL != (gInfo->lastColor =
  546.             (WORD **)AllocMem((LONG)sizeof(LONG) * 8, MEMF_CLEAR)))
  547.             {
  548.             if (NULL != (gInfo->collHandler =
  549.                 (struct collTable *)AllocMem((LONG)sizeof(struct collTable),
  550.                     MEMF_CLEAR)))
  551.                 {
  552.                 if (NULL != (vsHead = (struct VSprite *)AllocMem(
  553.                     (LONG)sizeof(struct VSprite), MEMF_CLEAR)))
  554.                     {
  555.                     if (NULL != (vsTail = (struct VSprite *)AllocMem(
  556.                         (LONG)sizeof(struct VSprite), MEMF_CLEAR)))
  557.                         {
  558.                         gInfo->sprRsrvd      = reserved;
  559.                         gInfo->leftmost      = 1;
  560.                         gInfo->rightmost  =
  561.                             (rPort->BitMap->BytesPerRow << 3) - 1;
  562.                         gInfo->topmost      = 1;
  563.                         gInfo->bottommost = rPort->BitMap->Rows - 1;
  564.  
  565.                         rPort->GelsInfo = gInfo;
  566.  
  567.                         InitGels(vsHead, vsTail, gInfo);
  568.  
  569.                         return(gInfo);
  570.                         }
  571.                     FreeMem(vsHead, (LONG)sizeof(*vsHead));
  572.                     }
  573.                 FreeMem(gInfo->collHandler, (LONG)sizeof(struct collTable));
  574.                 }
  575.             FreeMem(gInfo->lastColor, (LONG)sizeof(LONG) * 8);
  576.             }
  577.         FreeMem(gInfo->nextLine, (LONG)sizeof(WORD) * 8);
  578.         }
  579.     FreeMem(gInfo, (LONG)sizeof(*gInfo));
  580.     }
  581. return(NULL);
  582. }
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594. struct VSprite *makeVSprite(WORD y , WORD x , WORD flags, WORD width,
  595.                             WORD height, WORD depth , WORD memask,
  596.                             WORD hitmask, WORD *imagedata ,WORD *sprcolors )
  597. {
  598. struct VSprite *vsprite;
  599. LONG            line_size;
  600. LONG            plane_size;
  601.  
  602. line_size = (LONG)sizeof(WORD) * width;
  603. plane_size = line_size * height;
  604.  
  605. if (NULL != (vsprite =
  606.     (struct VSprite *)AllocMem((LONG)sizeof(struct VSprite), MEMF_CLEAR)))
  607.     {
  608.     if (NULL != (vsprite->BorderLine =
  609.         (WORD *)AllocMem(line_size, MEMF_CHIP)))
  610.         {
  611.         if (NULL != (vsprite->CollMask =
  612.             (WORD *)AllocMem(plane_size, MEMF_CHIP)))
  613.             {
  614.             vsprite->Y            = y;
  615.             vsprite->X            = x;
  616.             vsprite->Flags        = flags;
  617.             vsprite->Width        = width;
  618.             vsprite->Depth        = depth;
  619.             vsprite->Height        = height;
  620.             vsprite->MeMask        = memask;
  621.             vsprite->HitMask    = hitmask;
  622.             vsprite->ImageData    = imagedata;
  623.             vsprite->SprColors    = sprcolors;
  624.             vsprite->PlanePick    = 0x00;
  625.             vsprite->PlaneOnOff    = 0x00;
  626.  
  627.             InitMasks(vsprite);
  628.             return(vsprite);
  629.             }
  630.         FreeMem(vsprite->BorderLine, line_size);
  631.         }
  632.     FreeMem(vsprite, (LONG)sizeof(*vsprite));
  633.     }
  634. return(NULL);
  635. }
  636.  
  637.  
  638. VOID process_window(struct Window *win , struct Bob *ship_bob,
  639.                     struct Bob *enemy_bobs[] )
  640.  
  641. {
  642. WORD x = ship_bob->BobVSprite->X ;
  643.  
  644.  
  645. /* Direction of the sprite: */
  646. SHORT addit = 0;
  647. WORD x_direction = 0;
  648. UWORD frame = 0; /* Frame 0 */
  649. struct Bob *shoot[10] ;
  650. SHORT borderhit = 0;
  651. SHORT time = 0;
  652. short int beginshoot = 0;
  653. ULONG class; /* IDCMP */
  654. USHORT code; /* Code */
  655. UBYTE loop;
  656. WORD vx_direction = SPEED; 
  657. struct IntuiMessage *my_message;
  658. for(loop = 0;loop<10;loop++)
  659.     shoot[loop] = NULL;
  660. FOREVER
  661.     {
  662.     
  663.     while(my_message = (struct intuiMessage *)GetMsg(win->UserPort))
  664.         {
  665.         class = my_message->Class;
  666.          code  = my_message->Code;
  667.  
  668.         switch( class )
  669.             {
  670.             case CLOSEWINDOW:     /* Quit! */
  671.                 return;
  672.                 break; 
  673.  
  674.             case RAWKEY:          /* A key was pressed! */
  675.                                  /* Check which key was pressed: */
  676.                 switch( code )
  677.                     {
  678.                        /* Up Arrow: */
  679.                                case 0x4C:       break; /* Pressed */
  680.                                case 0x4C+0x80:
  681.                                         beginshoot = 1;
  682.                                         shoot[time] =makeBob(1,1,x+7 ,89,shoot_image,8,4,time);
  683.                     AddBob(shoot[time],win->RPort);
  684.                     bobDrawGlist(win);
  685.                     time = (time+1)%10; 
  686.                         break; /* Released */
  687.                     /* Right Arrow: */
  688.                     case 0x4E:      x_direction = 2; break; /* Pressed */
  689.                     case 0x4E+0x80: x_direction = 0; break; /* Released */
  690.  
  691.                     /* Left Arrow: */
  692.                     case 0x4F:      x_direction = -2; break; /* Pressed */
  693.                     case 0x4F+0x80: x_direction = 0;  break; /* Released */
  694.                     }
  695.                      break;
  696.             
  697.                 
  698.             }
  699.             ReplyMsg((struct Message *)my_message);
  700.         }
  701. if (beginshoot)
  702.     handle_shoot(shoot,win);
  703. DoCollision(win->RPort);     
  704.     /* Change the x/y position: */
  705.     x = x +  x_direction ;
  706.     
  707.  
  708.  
  709.                 
  710.     /* Check that the sprite does not move outside the screen: */
  711. if( x > win->Width - 21)
  712.     x = win->Width - 21;   
  713.      
  714. if(x< 1)
  715.     x = 1;
  716.     /* Move the sprite: */
  717.     
  718. ship_bob->BobVSprite->X = x;
  719.  
  720.  
  721.     /* Change frame: */
  722.     frame++;
  723.       
  724.     /* 6 frames: */
  725.     if( frame > 5 )
  726.       frame = 0;
  727.     
  728.     for( loop = 0; loop < MAXBOBS; loop++ )
  729.         {
  730.         if(enemy_bobs[ loop ])
  731.             {
  732.  
  733.                         /* Change the x position of the VSprite: */
  734.             if (enemy_bobs[loop]->BobVSprite->Y >=80)
  735.                 quit(0);
  736.             enemy_bobs[ loop ]->BobVSprite->X += vx_direction;
  737.                     /* Check that the sprite does not move outside the screen: */
  738.             if(enemy_bobs[ loop ]->BobVSprite->X >=win->Width-36 )
  739.                 borderhit = 1;
  740.             else
  741.                 if(enemy_bobs[ loop ]->BobVSprite->X <= 2)
  742.                     borderhit = 1;
  743.                 
  744.             
  745.  
  746.  
  747.                 
  748.                  /* Change the image of the VSprite: */
  749.                  enemy_bobs[ loop ]->BobVSprite->ImageData = ship_data[ frame + addit];
  750.             InitMasks(enemy_bobs[ loop ]->BobVSprite);
  751.             }
  752.         }  
  753.     bobDrawGlist(win);
  754.     if(borderhit)
  755.          {
  756.          for( loop = 0; loop < MAXBOBS; loop++ )
  757.             if(enemy_bobs[ loop ])
  758.                 enemy_bobs[ loop ]->BobVSprite->Y +=4;
  759.  
  760.          vx_direction = -vx_direction;
  761.              borderhit = 0;
  762.              if (vx_direction > 0)
  763.              addit = 0;
  764.          else
  765.              addit = 6;
  766.          }     
  767.     }
  768. }
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776. struct Bob *makeBob(SHORT wordwidth,SHORT lineheight,SHORT x,
  777.                     SHORT y, WORD *imagedata,WORD memask,
  778.                     WORD hitmask,SHORT id )
  779. {
  780. struct Bob       *bob;
  781. struct VSprite       *vsprite;
  782. LONG    rassize;
  783. WORD flags = SAVEBACK | OVERLAY;
  784. rassize = (LONG)sizeof(UWORD) * wordwidth * lineheight * 2 ;
  785.  
  786. if (NULL != (bob =
  787.     (struct Bob *)AllocMem((LONG)sizeof(struct Bob), MEMF_CLEAR)))
  788.     {
  789.     if (NULL != (bob->SaveBuffer = (WORD *)AllocMem(rassize, MEMF_CHIP)))
  790.         {
  791.         if ((vsprite =
  792.         makeVSprite(y,x,flags,wordwidth,lineheight,2,memask,hitmask,imagedata,NULL)) != NULL)
  793.             {
  794.             vsprite->PlanePick = 3;
  795.             vsprite->PlaneOnOff = 0;
  796.  
  797.             vsprite->VSBob     = bob;
  798.             bob->BobVSprite     = vsprite;
  799.             bob->ImageShadow = vsprite->CollMask;
  800.             bob->Flags     = 0;
  801.             bob->Before     = NULL;
  802.             bob->After     = NULL;
  803.             bob->BobComp     = NULL;
  804.             bob->DBuffer     = NULL;
  805.             bob->BUserExt = id;
  806.             return(bob);
  807.             }
  808.  
  809.         freeVSprite(vsprite);
  810.         }
  811.     FreeMem(bob, (LONG)sizeof(*bob));
  812.     }
  813. return(NULL);
  814. }
  815. VOID bobDrawGlist(struct Window *win)
  816. {
  817. SortGList(win->RPort);
  818. DrawGList(win->RPort,ViewPortAddress(win));
  819. WaitTOF();
  820. }
  821.  
  822. VOID handle_shoot(struct Bob *shoot[],struct Window *win)
  823. {
  824. int i;
  825. for(i = 0;i<10;i++)
  826.     {
  827.     if (shoot[i] != NULL )
  828.         {
  829.         if (shoot[i]->BobVSprite->Y <= 12) 
  830.             {
  831.             RemBob(shoot[i]);
  832.             /*freeBob(shoot[i]);*/
  833.             shoot[i] = NULL;
  834.             }
  835.         else 
  836.             shoot[i]->BobVSprite->Y -=3;
  837.         }
  838.     }
  839. /*bobDrawGlist(win);*/
  840.  
  841. }
  842.  
  843.  
  844.  
  845. VOID gotit(struct VSprite *gelA,struct VSprite *gelB)
  846. {
  847.  
  848. struct Bob *bb;
  849.  
  850.  
  851. bb = gelA->VSBob;
  852. if (gelA->Width == 3)
  853.     enemy_bobs[bb->BUserExt] = NULL;
  854. RemBob(bb);
  855. /*freeBob(bb);*/
  856. bb = gelB->VSBob;
  857. if (gelB->Width == 3)
  858.     enemy_bobs[bb->BUserExt] = NULL;
  859. RemBob(bb);
  860. /*freeBob(bb);*/
  861. bobDrawGlist(win);
  862.  
  863. }
  864.  
  865. VOID freeBob(struct Bob *bob)
  866. {
  867. LONG rassize;
  868.  
  869. rassize = (LONG)sizeof(UWORD) * bob->BobVSprite->Width * bob->BobVSprite->Height * 2;
  870.  
  871. FreeMem(bob->SaveBuffer,rassize);
  872. freeVSprite(bob->BobVSprite);
  873. FreeMem(bob,(LONG)sizeof(*bob));
  874. }
  875.  
  876.  
  877. VOID do_bobs(struct Window *win)
  878.  
  879.  
  880.  
  881.  
  882.  
  883. SHORT loop, i;
  884. SHORT vx = 0,vy =0;     /* X and Y position.                */
  885.  
  886. if (NULL == (my_ginfo = setupGelSys(win->RPort, 0xfc)))
  887.     return_code = RETURN_WARN;
  888. else
  889.     {
  890.     if(NULL == (ship_bob = makeBob(2,8,20,90,good_ship_data,0,0,0)))
  891.         return_code = RETURN_WARN;
  892.     else
  893.         {
  894.         AddBob(ship_bob,win->RPort);
  895.         for(loop = 0; loop < MAXBOBS ; loop++)
  896.             {
  897.              if (NULL == (enemy_bobs[ loop ]=makeBob(3,12,20 * vx+4,20 * vy + 13,ship_data[0],4,8,loop )))
  898.                 {
  899.                 return_code = RETURN_WARN;
  900.                 break;
  901.                 }
  902.             else
  903.                 {
  904.                 AddBob(enemy_bobs[ loop ], win->RPort);
  905.                 
  906.                 vx = vx + 2;                
  907.                 if( vx > 7)
  908.                     {
  909.                     vx = 0;
  910.                     vy++;
  911.                     }        
  912.                 }
  913.             }
  914.         if(loop >= MAXBOBS)
  915.             {
  916.             bobDrawGlist(win);
  917.             SetCollision(2,gotit,win->RPort->GelsInfo);
  918.             SetCollision(3,gotit,win->RPort->GelsInfo);
  919.             process_window(win,ship_bob,enemy_bobs);
  920.             }        
  921.         for(i = 0; i <loop;i++)
  922.             {
  923.             if(enemy_bobs[i])
  924.                 {                
  925.                 RemBob(enemy_bobs[i]);
  926.                 /*freeBob(enemy_bobs[i]);*/
  927.                 }
  928.             }
  929.         if(ship_bob)
  930.             {
  931.             RemBob(ship_bob);
  932.             /*freeBob(ship_bob);*/
  933.             }
  934.         bobDrawGlist(win);
  935.         }            
  936.     cleanupGelSys(my_ginfo,win->RPort);
  937.     }
  938. }
  939.  
  940.  
  941. VOID bordercheck(struct VSprite *vs,LONG borderflags)
  942. {
  943. printf("yes yes yes yes yes");
  944. }
  945.  
  946.  
  947. VOID quit(int return_code)
  948. {
  949. int i;
  950. for(i = 0; i <MAXBOBS;i++)
  951.     {
  952.     if(enemy_bobs[i])
  953.         {                
  954.         RemBob(enemy_bobs[i]);
  955.         /*freeBob(enemy_bobs[i]);*/
  956.         }
  957.     }
  958. if(ship_bob)
  959.     {
  960.     RemBob(ship_bob);
  961.     /*freeBob(ship_bob);*/
  962.     }
  963. bobDrawGlist(win);
  964.     
  965.         
  966. cleanupGelSys(my_ginfo,win->RPort);
  967. CloseWindow(win);
  968. CloseLibrary(IntuitionBase);
  969. CloseLibrary(GfxBase);
  970. exit(return_code);
  971. }
  972.